Imports ClubStarterKit.Web
Imports System.Data.Linq
Imports System.Linq


Partial Class Statistics_NewGame
    Inherits System.Web.UI.Page

    Private m_selectedseasonid As Integer = 0
    Public Property SelectedSeason() As Integer
        Get
            Return m_selectedseasonid
        End Get
        Set(ByVal value As Integer)
            m_selectedseasonid = value
        End Set
    End Property


    Protected Sub AddGame_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddGame.Click


        'If Team1DropDown.SelectedValue = Team2DropDown.SelectedValue Then
        '    ErrorStatus.Text = "<strong>Please select 2 different teams.</strong>"
        'Else
        '    Dim newid As Integer = ClubStarterKit.Web.League.AddGame(Integer.Parse(Team1DropDown.SelectedValue.ToString()), Integer.Parse(Team2DropDown.SelectedValue.ToString()), Integer.Parse(SeasonsDropDown.SelectedValue.ToString()), CDate(DateTXT.Text).Add(TimePicker1.SelectedTime.TimeOfDay))
        '    Response.Redirect("~/CricketStats/game.aspx?id=" & newid.ToString())
        'End If

        Using db As New CricketBLL.CricketStatsDataContext(Settings.DatabaseConnectionString)

            Dim match As New CricketBLL.Match
            match.MatchDate = CDate(DateTXT.Text + " " + ddlStartTime.SelectedItem.Text)
            match.TeamId = CInt(TeamDropDown.SelectedValue)
            match.OpponentTeam = txtOpposition.Text
            match.SeasonId = CInt(SeasonsDropDown.SelectedValue)
            match.IsHome = IIf(rblHomeAway.SelectedValue.ToLower().Equals("home"), True, False)

            db.Matches.InsertOnSubmit(match)

            db.SubmitChanges()


        End Using

        Response.Redirect("~/CricketStats/default.aspx")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            Using db As New CricketBLL.CricketStatsDataContext(Settings.DatabaseConnectionString)

                'Seasons
                Dim seasons = From s In db.Seasons _
                              Select s
                SeasonsDropDown.DataSource = seasons
                SeasonsDropDown.DataBind()

                'Teams
                Dim teams = From t In db.Teams _
                            Select t
                TeamDropDown.DataSource = teams
                TeamDropDown.DataBind()


            End Using

            'SelectedSeason() = ClubStarterKit.Web.Settings.CurrentSeason()
        End If
        'ObjectDataSource1.SelectParameters(0).DefaultValue = SelectedSeason()
    End Sub

End Class
